// component/common/com-cooperative-advisory-item/com-cooperative-advisory-item.js
import { formatDateTime } from "../../../utils/util";
import { houseInfoBehavior } from "../../../behaviors/houseInfo";
import { getActiveStr } from "../../../utils/utilsNew";

Component({
  behaviors: [houseInfoBehavior],

  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
      value: {},
    },
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    _info: {},
  },

  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      let info = { ...this.data.info };
      info.realName = getActiveStr(info.realName, 6);
      info.lastCommunicateTime = formatDateTime(info.lastCommunicateTime || item.talkingTime, true);
      info.detailInfo = this.getHousePreviewInfo(info);
      this.setData({
        _info: info,
      });
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleCopyPhoneNum() {
      wx.setClipboardData({
        data: this.data._info.wxMobile,
        success: () => {
          wx.showToast({
            title: "手机号复制成功",
          });
        },
      });
    },
    handlePhone(e) {
      const info = e.detail
      this.triggerEvent("onvmvisible", {
        visible: true,
        cooperationId: info.houseCooperationId,
        toUserId:info.toUserId
      });
    },
  },
});
